<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta content="phalconplus API doc" name="description">
    <title>
                    phalconplus API Documentation
            </title>
    <link rel="stylesheet" type="text/css" href="../../../asset/static/prettify.css" />

<script src="../../../asset/static/prettify.js"></script>
<script src="../../../asset/api_definition.js"></script>


                        <link rel="stylesheet" type="text/css" href="../../../asset/static/prettify.css" />
                    <link rel="stylesheet" type="text/css" href="../../../asset/static/zephir-theme.css" />
            
    

                        <script src="../../../asset/static/prettify.js"></script>
                                    <script src="../../../asset/api_definition.js"></script>
                    <script src="../../../asset/static/jquery.min.js"></script>
                    <script src="../../../asset/static/zephir-doc.js"></script>
                <script type="application/javascript">let ZepCurrentPath = '../../../'</script>
    </head>
 <body onload="prettyPrint()">
        <div id="top-bar">
            <div id="top-left">
                                    phalconplus Documentation <span class="version">v1.1.1</span>
                            </div>
            <div id="top-right">
            </div>
        </div>
        <div id="body">
            <div id="body-left">
                <div class="header-search">
                    <input class="search-box" placeholder="Search for a class or namespace " type="text" />
                    <div id="menu-wrapper">
                    </div>
                </div>
            </div>
            <div id="body-right">
                <div class="content">
                    
<div class="breadcrumb">
    
    <ul>
        
        <li><a href="../../../index.html">Home</a></li>
        
                <li><a href="../../../classes.html">Classes</a></li>
                <li><a href="../../../class/PhalconPlus/Curl/Response.html">PhalconPlus\Curl\Response</a></li>
                <li><a >Source</a></li>
                
    </ul>
    
</div>
<div class="class-header source clearfix">
    
    <div class="access-buttons">
        <a class="zep-button" href="../../../class/PhalconPlus/Curl/Response.html">Class</a>

            </div>
    
    <div class="class-full-name">
        <span class="class-type">Class</span>
        
                <span class="namespace-piece">
            <a href="../../../namespace/PhalconPlus.html">PhalconPlus</a>
        </span>
                <span class="namespace-piece">
            <a href="../../../namespace/PhalconPlus/Curl.html">Curl</a>
        </span>
        
        <h1 class="class-name">Response</h1>
    </div>
    
</div>

<pre class="zephir-source-file prettyprint linenums">
    namespace PhalconPlus\Curl;

class Response
{
	/**
	 * The response headers.
	 *
	 * @var array
	 */
     public headers = [];
     /**
      * The response body.
      *
      * @var string
      */
     public body = "" { get };
     /**
      * The results of curl_getinfo on the response request.
      *
      * @var array|false
      */
     public info = [];
     /**
      * The response code including text, e.g. '200 OK'.
      *
      * @var string
      */
     public statusText = "" { get };
     /**
      * The response code.
      *
      * @var int
      */
     public statusCode { get };
     /**
      * @param string $body
      * @param string $headers
      * @param mixed  $info
      */
     public function __construct(string body, string headers, var info = [])
     {
         let this->body = body;
         let this->info = info;
         this->parseHeader(headers);
     }
     /**
      * Parse a header string.
      *
      * @param  string $header
      *
      * @return void
      */
     protected function parseHeader(string header)
     {
         var headers = [];
         let headers = explode("\r\n", trim(header));
         this->parseHeaders(headers);
     }
     /**
      * Parse an array of headers.
      *
      * @param  array  $headers
      *
      * @return void
      */
     protected function parseHeaders(array headers)
     {
         let this->headers = [];
         // find and set the HTTP status code and reason
         var firstHeader = array_shift(headers);
         // HTTP/1.1 200 OK
         if (!preg_match("/^HTTP\/\d(\.\d)? [0-9]{3}/", firstHeader)) {
             throw new \InvalidArgumentException("Invalid response header");
         }
         var code, status, parts;
         let parts = explode(" ", firstHeader, 2);

         let status = parts[1];
         let code = explode(" ", status);
         let code = intval(code[0]);

         var key, header, headerCopy = headers;
         // special handling for HTTP 100 responses
         if (code === 100) {
             // remove empty header lines between 100 and actual HTTP status
             for key, header in headerCopy {
                 if (header) {
                     break;
                 }
                 unset(headers[key]);
             }
             // start the process over with the 100 continue header stripped away
             return this->parseHeaders(headers);
         }
         let this->statusText = status;
         let this->statusCode = code;

         for header in headers {
             // skip empty lines
             if (!header) {
                 continue;
             }
             var delimiter = strpos(header, ":");
             if (!delimiter) {
                 continue;
             }
             var key, val;
             let key = trim(strtolower(substr(header, 0, delimiter)));
             let val = ltrim(substr(header, delimiter + 1));
             if (isset(this->headers[key])) {
                 if (is_array(this->headers[key])) {
                     let this->headers[key][] = val;
                 } else {
                     let this->headers[key] = [this->headers[key], val];
                 }
             } else {
                 let this->headers[key] = val;
             }
         }
     }
     /**
      * Get a specific header from the response.
      *
      * @param  string $key
      *
      * @return mixed
      */
     public function getHeader(key)
     {
         let key = strtolower(key);
         return isset(this->headers[key]) ? this->headers[key] : null;
     }
     /**
      * Gets all the headers of the response.
      *
      * @return array
      */
     public function getHeaders()
     {
         return this->headers;
     }
     /**
      * Convert the response instance to an array.
      *
      * @return array
      */
     public function toArray()
     {
         return [
             "headers" : this->headers,
             "body"    : this->body,
             "info"    : this->info
         ];
     }
     /**
      * Convert the response object to a JSON string.
      *
      * @return string
      */
     public function toJson()
     {
         return json_encode(this->toArray());
     }

     public function jsonSerialize()
     {
        return this->toArray();
     }

     /**
      * Convert the object to its string representation by returning the body.
      *
      * @return string
      */
     public function __toString()
     {
         return this->body;
     }
}</pre>
                </div>
            </div>
        </div>
    </body>
</html>
